package it.lovaex.scb.unittests;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import it.lovaex.scb.factory.DiscountRateFactory;
import it.lovaex.scb.factory.IDiscountRateFactory;

import org.junit.Before;
import org.junit.Test;

public class DiscountRateFactoryTest {

	IDiscountRateFactory sut;
	
	@Before
	public void setUp(){
		sut = new DiscountRateFactory();
	}
	
	@Test
	public void test_get_discount_by_total_under_or_equal_threshold() {
		BigDecimal totUnderThreshold = BigDecimal.valueOf(39);
		BigDecimal result = sut.getByTotal(totUnderThreshold);
		assertEquals(BigDecimal.ZERO, result);
		
		totUnderThreshold = BigDecimal.valueOf(0);
		result = sut.getByTotal(totUnderThreshold);
		assertEquals(BigDecimal.ZERO, result);
		
		totUnderThreshold = BigDecimal.valueOf(-1);
		result = sut.getByTotal(totUnderThreshold);
		assertEquals(BigDecimal.ZERO, result);
		
		totUnderThreshold = BigDecimal.valueOf(40);
		result = sut.getByTotal(totUnderThreshold);
		assertEquals(BigDecimal.ZERO, result);
	}
	
	@Test
	public void test_get_discount_by_total_over_threshold() {
		BigDecimal totUnderThreshold = BigDecimal.valueOf(40.01);
		BigDecimal result = sut.getByTotal(totUnderThreshold);
		BigDecimal expected = BigDecimal.valueOf(0.05);
		assertEquals(expected, result);
		
		totUnderThreshold = BigDecimal.valueOf(41);
		result = sut.getByTotal(totUnderThreshold);
		assertEquals(expected, result);
		
		totUnderThreshold = BigDecimal.valueOf(100);
		result = sut.getByTotal(totUnderThreshold);
		assertEquals(expected, result);
	}

	@Test
	public void test_get_by_itemcode(){
		String itemCode = "an item code";
		BigDecimal result = sut.getByItemCode(itemCode);
		BigDecimal expected = BigDecimal.ZERO;
		assertEquals(expected, result);
		
		itemCode = "Chocolate";
		result = sut.getByItemCode(itemCode);
		expected = BigDecimal.ZERO;
		assertEquals(expected, result);
		
		itemCode = "Grocery";
		result = sut.getByItemCode(itemCode);
		expected = BigDecimal.valueOf(0.075);
		assertEquals(expected, result);
		
		itemCode = "Book";
		result = sut.getByItemCode(itemCode);
		expected = BigDecimal.valueOf(0.12);
		assertEquals(expected, result);
		
		itemCode = "any other itemcode";
		result = sut.getByItemCode(itemCode);
		expected = BigDecimal.ZERO;
		assertEquals(expected, result);
	}
}
